package com.mq.service.impl;


import java.util.Map;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import com.mq.service.IMqSendService;

@Component
@Service
public class MqSendServiceImpl  implements IMqSendService{
	
	@Autowired
    RabbitTemplate rabbitTemplate;  //使用RabbitTemplate,这提供了接收/发送等等方法
	
	/**
	 * direct Exchange 类型信息发送 fanout、topic
	 */
	public String sendMessage( Map<String,Object> map) {
		
        if(map != null && !map.isEmpty()) {        	
            //将消息携带绑定键值：TestDirectRouting 发送到交换机TestDirectExchange
            rabbitTemplate.convertAndSend("TestDirectExchange", "TestDirectRouting", map);
            return "消息推送成功";
        }else {
        	return "消息体为空，不可推送！";
        }
        
        
	}
	/**
	 * topicExchange 交换机
	 * topic Exchange 类型信息发送 
	 */
	public String sendTopicMessage( Map<String,Object> map) {
		
        if(map != null && !map.isEmpty()) {        	
            //将消息携带绑定键值：TestDirectRouting 发送到交换机TestDirectExchange
        	rabbitTemplate.convertAndSend("topicExchange", "topic.man", map);
        	//rabbitTemplate.convertAndSend("TestDirectExchange", "TestDirectRouting", map);
            return "消息推送成功";
        }else {
        	return "消息体为空，不可推送！";
        }
        
        
	}
	/**
	 * Fanout Exchang 扇型交换机
	 * fanout Exchange 类型信息发送 、
	 */
	public String sendFanoutMessage( Map<String,Object> map) {
		
        if(map != null && !map.isEmpty()) {        	
            //将消息携带绑定键值：TestDirectRouting 发送到交换机TestDirectExchange
        	rabbitTemplate.convertAndSend("fanoutExchange", null, map);
        	//rabbitTemplate.convertAndSend("TestDirectExchange", "TestDirectRouting", map);
            return "消息推送成功";
        }else {
        	return "消息体为空，不可推送！";
        }
        
        
	}
}
